package util.AST.Comando;

import java.util.ArrayList;

import util.AST.Expressao.Expressao;

public class IfElse extends ComandoSimples{
	
	private Expressao expressao;
	private ArrayList<Comando> comandoIf;
	private ArrayList<Comando> comandoElse;
	
	public IfElse(Expressao expressao, ArrayList<Comando> comandoIf, ArrayList<Comando> comandoElse){
		this.expressao = expressao;
		this.comandoIf = comandoIf;
		this.comandoElse = comandoElse;
	}
	
	public Expressao getExpressao(){
		return this.expressao;
	}
	
	public ArrayList<Comando> getComandoIf(){
		return this.comandoIf;
	}
	
	public ArrayList<Comando> getComandoElse(){
		return this.comandoElse;
	}
	
	
	@Override
	public String toString(int level) {
		int nextLevel = level + 5;
		StringBuffer string = new StringBuffer();
		string.append("IF\n");
		string.append(super.getSpaces(nextLevel) + "|-Expressao\n" );
		string.append(super.getSpaces(nextLevel) + "|-");
		if(this.expressao != null){
			string.append(this.expressao.toString(nextLevel + 5));
		}
		string.append(super.getSpaces(nextLevel) + "|-COMANDO IF\n");
		if(this.comandoIf != null){
			for(Comando comando : this.comandoIf){
				string.append(super.getSpaces(nextLevel + 5)  + "|-");
				string.append(comando.toString(nextLevel + 5));
			}
		}
		string.append(super.getSpaces(nextLevel) + "|-COMANDO ELSE\n");
		if(this.comandoElse != null){
			for(Comando comando : this.comandoElse){
				string.append(super.getSpaces(nextLevel + 5) + "|-");
				string.append(comando.toString(nextLevel + 5));
			}
		}
		string.append(super.getSpaces(nextLevel) + "|-END\n");
		return string.toString();
	}

}
